package com.fanshilz.flower2025.framework.resp;

import cn.hutool.http.HttpStatus;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;

@Data
@NoArgsConstructor
@AllArgsConstructor
public class Resp<D> implements Serializable {

    private Boolean success;

    private D data;

    private Integer errorCode;

    private String errorMessage;

    private Integer showType;

    private String traceId;

    private String host;

    public static <D> Resp<D> success(D data) {
        return base(true, data, HttpStatus.HTTP_OK, null, null);
    }

    public static <D> Resp<D> success(String message) {
        return base(true, null, HttpStatus.HTTP_OK, message, null);
    }

    public static <D> Resp<D> success() {
        return base(true, null, HttpStatus.HTTP_OK, null, null);
    }

    public static <D> Resp<D> error(String errorMessage) {
        return base(false, null, HttpStatus.HTTP_INTERNAL_ERROR, errorMessage, null);
    }

    public static <D> Resp<D> error(Integer errorCode, String errorMessage) {
        return base(false, null, errorCode, errorMessage, null);
    }

    public static <D> Resp<D> error() {
        return base(false, null, HttpStatus.HTTP_INTERNAL_ERROR, null, null);
    }

    public static <D> Resp<D> base(Boolean success, D data, Integer errorCode, String errorMessage, Integer showType) {
        return new Resp<>(success, data, errorCode, errorMessage, showType, "SpringContext.traceId()", "SpringContext.HOST");
    }

}
